package com.example.coinhelper.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class UserDBHelper extends SQLiteOpenHelper {

    // 数据库名称和版本
    public static final String DATABASE_NAME = "coin.db";
    public static final int DATABASE_VERSION = 1;

    // 表名和列名
    public static final String TABLE_NAME = "user_table";

    public static final String COLUMN_USERNAME = "username";
    public static final String COLUMN_PASSWORD = "password";
    public static final String COLUMN_NAME = "name";
    public static final String COLUMN_ICON = "icon";
    public static final String COLUMN_GENDER = "gender";
    public static final String COLUMN_REGISTRATION_TIME = "registration_time";
    public static final String COLUMN_MONEY = "money";
    public static final String COLUMN_SIGNATURE = "signature";// 创建用户表的 SQL 语句
    private static final String CREATE_TABLE_USERS =
            "CREATE TABLE " + TABLE_NAME + " (" +
                    COLUMN_USERNAME + " TEXT PRIMARY KEY," + // 主键
                    COLUMN_PASSWORD + " TEXT NOT NULL," + // 非空
                    COLUMN_NAME + " TEXT," +
                    COLUMN_ICON + " integer," +
                    COLUMN_GENDER + " TEXT," +
                    COLUMN_REGISTRATION_TIME + " TEXT," +
                    COLUMN_SIGNATURE + " TEXT, " +
                    COLUMN_MONEY + " REAL" +
                    ")";
    public UserDBHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        // 创建用户表
        db.execSQL(CREATE_TABLE_USERS);
        db.execSQL(DetailsDBHelper.CREATE_DETAILS_TABLE);
        db.execSQL(NoteDBHelper.SQL_CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // 升级数据库时执行的操作，可以在这里处理数据库的更新
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
        onCreate(db);
    }
}
